package com.prothink.controller;

import com.prothink.entity.JsCourse;
import com.prothink.entity.RequestData;
import com.prothink.service.JsCourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName : JsCourseController  //类名
 * @Description : 课程mvc  //描述
 * @Author : Zhang //作者
 * @Date: 11/21  10:58
 */
@CrossOrigin
@RestController
@RequestMapping("/course")
public class JsCourseController {

    @Autowired
    private JsCourseService courseService;

    /**
     * 获取课程数据
     */
    @RequestMapping("/getCourse")
    public RequestData getCourse() {
        List<JsCourse> courseList = courseService.getCourse();
        if (courseList != null) {
            return RequestData.buildSuccess(courseList);
        }
        return null;
    }
    /*
     * 高级检索查询数据
     */
    @RequestMapping("/getCourseJS")
    public RequestData getCourseJS(@RequestBody JsCourse jsCourse) {
        List<JsCourse> courseList = courseService.getCourseJS(jsCourse);
        if (courseList != null) {
            return RequestData.buildSuccess(courseList);
        }
        return null;
    }

    /**
     * 删除课程
     */
    @GetMapping("/deleteCourse")
    public RequestData deleteCourse(Integer courseId) {
        Boolean aBoolean = courseService.deleteCourse(courseId);
        if (aBoolean) {
            return RequestData.success();
        }
        return null;
    }
    /*
     * 添加课程
     */
    @RequestMapping("/addCourse")
    public RequestData addCourse(@RequestBody JsCourse jsCourse){
        Boolean aBoolean = courseService.addCourse(jsCourse);
        if (aBoolean){
            return RequestData.buildSuccess(aBoolean);
        }
        return null;
    };

}
